#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.db import connection
from web.dao.base_dao import BaseDao
from web.models.stock_index import StockIndex

"""
StockIndex的dao类
"""


class StockIndexDao(BaseDao):
    model_class = StockIndex

    def find_date_and_close_price_by_code_between_date_order_by_date_asc(self, code, begin_date, end_date):
        """
        根据code，查询一段时间内的收盘价，并按照日期升序排列
        """

        with connection.cursor() as cursor:
            cursor.execute("select t.date_, t.close_price from stock_index t "
                           "where t.date_ between to_date(%s,'yyyy-mm-dd') "
                           "and to_date(%s,'yyyy-mm-dd') and t.code_=%s "
                           "order by t.date_ asc", (begin_date, end_date, code))
            close_price_tuple = cursor.fetchall()
            return close_price_tuple
